package com.stevenmoon.csdnplus.net;

import com.zhy.http.okhttp.builder.PostFormBuilder;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Created by WangJun on 2016/4/7.
 */
public class NetPostBuilder extends PostFormBuilder {

    public NetPostBuilder(){
        this.params = new LinkedHashMap<>();
        this.headers = new LinkedHashMap<>();
    }

    @Override
    public NetPostBuilder url(String url)
    {
        this.url = url;
        return this;
    }

    @Override
    public NetPostBuilder params(Map<String, String> params)
    {
        this.params = params;
        return this;
    }

    @Override
    public NetPostBuilder addParams(String key, String val)
    {
        if (this.params == null)
        {
            params = new LinkedHashMap<>();
        }
        params.put(key, val);
        return this;
    }

    /**
     * Adds a int value to the request.
     *
     * @param key   the key name for the new param.
     * @param value the value int for the new param.
     */
    public NetPostBuilder addParams(String key, int value) {
        if (key != null) {
            params.put(key, String.valueOf(value));
        }
        return this;
    }

    /**
     * Constructs a new RequestParams instance containing the key/value string params from the
     * specified map.
     *
     * @param params the source key/value string map to add.
     */
    public NetPostBuilder addParams(Map<String, String> params)
    {

        if (params != null) {
            for (Map.Entry<String, String> entry : params.entrySet()) {
                this.params.put(entry.getKey(), entry.getValue());
            }
        }
        return this;
    }



    @Override
    public NetPostBuilder headers(Map<String, String> headers)
    {
        this.headers = headers;
        return this;
    }


    @Override
    public NetPostBuilder addHeader(String key, String val)
    {
        headers.put(key, val);
        return this;
    }

    @Override
    public PostFormBuilder tag(Object tag)
    {
        this.tag = tag;
        return this;
    }


}
